$(function () {

    //根据邀约组获取组员
    $('#invitgroup').change(function () {
        $('#yykf').empty();
        $("<option value=''>" + '选择邀约人员' + "</option>").appendTo($('#yykf'));
        $.post("/adminnew/common/getuserByGroup",{depart_id:$('#invitgroup').val()},function (data) {
            $.each(eval(data), function (i, n) {
                $("<option value='" + n.id + "'>" + n.username + "</option>").appendTo($('#yykf'));
            });
        });
    });

    //联动渠道获取来源和班级
    $('#channels').on('hidden.bs.select',function () {
        var channel = $(this).selectpicker('val');
        var obj = $('#source0');
        $.post("/adminnew/common/getSourceByChennel", {channel:channel}, function (result) {
            var html = "";
            obj.html('');
            if (result == '') {
                html += "<option value='0' selected='selected'>暂无来源</option>";
                $('#banjishow').hide();
                $('#xingqi').hide();
                $('#shangkeriqi').hide();
                obj.append(html);
            } else {
                $.each(eval(result), function (i, n) {
                    $("<option value='" + n.id + "' selected='selected' >" + n.title + "</optinon>").appendTo(obj);
                });
            }
            var banji = $('#banji');
            $.post("/adminnew/common/getBanjiBySource", {source: channel}, function (result) {
                var html = "";
                banji.html('');
                if(result.code==0){
                    return false;
                } else {
                    if (result == '') {
                        $('#banjishow').hide();
                        $('#xingqi').hide();
                        $('#shangkeriqi').hide();
                        html += "<option value='0' selected='selected'>暂无班级</option>";
                        banji.append(html);
                    }else{
                        $('#banjishow').show();
                        $('#xingqi').show();
                        $('#shangkeriqi').show();
                        $.each(eval(result), function (i, n) {
                            $("<option value='" + n.id + "' selected='selected'>" + n.banjiname + "</optinon>").appendTo(banji);
                        });
                    }
                }
            })

        });
    });

});